<?php

class Core_Action_Admin_Setting_Mail_Template_Create extends Action_Admin
{

	public function execute($request, $initial = FALSE, $script = NULL)
	{
		if ($initial)
		{
			Agilet::setVar('breadcrum', array(
				array(
					'url' => 'admin/seting',
					'label' => 'Setting'
				),array(
					'url' => 'admin/seting/mail',
					'label' => 'Mail'
				),
				array(
					'url' => 'admin/setting/mail/template',
					'label' => 'Template'
				),
				array(
					'url' => 'admin/setting/mail/template/create',
					'label' => 'Create Mail Template'
				)
			));

		}

		$table = Model::getTable('core/mailtemplate');

		$form = Form::factory('core/admin/mailtemplate/edit');

		if ($request -> isGet() && $item)
		{
			// $form -> setData($item -> toArray());
		}

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getData();

			$item = $table -> fetchNew();

			$item -> setFromArray($data);

			$item -> created_at = time();

			$item -> updated_at = time();

			$item -> save();

			$form -> setNotice('Saved Successful!');
		}

		$request -> response = View::render($script = 'core/html/admin/edit', $data = array(
			'title' => 'Edit Mail Template',
			'form' => $form
		));
	}

}
